<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">结算订单</div>
                </div>
                <div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-cf">
                        <form class="toolbar-form" action="" id="form-search" autocomplete="off">
                            <div class="am-u-sm-12 am-u-md-3" style="position: absolute">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <?php if (checkPrivilege('server.order/export')): ?>
                                                <a class="j-export am-btn am-btn-success am-radius"
                                                   href="javascript:void(0);">
                                                    <i class="iconfont icon-daochu am-margin-right-xs"></i>订单导出
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <input type="hidden" name="dataType" value="all">
                            <input type="hidden" name="s" value="/<?= $request->pathinfo() ?>">
                            <input type="hidden" name="user_id" value="<?= $request->get('user_id') ?>">
                            <div class="am-u-sm-12 am-u-md-9 am-u-sm-push-3">
                                <div class="am fr">
                                    <div class="am-form-group am-fl">
                                        <select name="is_settled"
                                                data-am-selected="{btnSize: 'sm', placeholder: '是否结算佣金'}">
                                            <option value=""></option>
                                            <option value="-1" <?= $request->get('is_settled') == '-1' ? 'selected' : '' ?>>
                                                全部
                                            </option>
                                            <option value="0" <?= $request->get('is_settled') === '0' ? 'selected' : '' ?>>
                                                未结算
                                            </option>
                                            <option value="1" <?= $request->get('is_settled') == '1' ? 'selected' : '' ?>>
                                                已结算
                                            </option>
                                        </select>


                                    </div>

                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="start_time"
                                               class="am-form-field"
                                               value="<?= $request->get('start_time') ?>" placeholder="请选择起始日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="end_time"
                                               class="am-form-field"
                                               value="<?= $request->get('end_time') ?>" placeholder="请选择截止日期"
                                               data-am-datepicker>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入服务人员" value="<?= $request->get('search') ?>">
                                        </div>
                                    </div>
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                        <input type="text" class="am-form-field" name="phone"
                                               placeholder="请输入客户电话/订单号" value="<?= $request->get('phone') ?>">
                                        <div class="am-input-group-btn">
                                            <button class="am-btn am-btn-default am-icon-search"
                                                    type="submit"></button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="order-list am-scrollable-horizontal am-u-sm-12 am-margin-top-xs">
                        <table width="100%" class="am-table am-table-centered
                        am-text-nowrap am-margin-bottom-xs" style="white-space: unset;">
                            <thead>
                            <tr>
                                <th>订单号/预约类型</th>
                                <th>日期/时间段</th>
                                <th>渠道</th>
                                <th width="10%">服务人员
                                    <p><span>（姓名/联系方式）</span></p>
                                </th>
                                <th width="10%">客户信息
                                    <p><span>（姓名/电话/地址）</span></p>
                                </th>
                                <th width="15%">服务信息
                                    <p><span>开始/结束/工作时长/服务数量</span></p>
                                </th>
                                <th width="15%" style="white-space: pre-line;">客户评价
                                    <p><span>评价内容</span></p>
                                </th>
                                <th width="7%">服务内容
                                    <p><span>审核备注</span></p>
                                </th>
                                <th width="10%">金额
                                    <p><span>订单/服务费用/实际支付</span></p>
                                </th>
                                <th width="7%">支付状态
                                    <p><span>订单类型</span></p>
                                </th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (!$list->isEmpty()): foreach ($list as $item): ?>
                                <tr>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['order_no'] ?></span></p>
                                        <p><span><?= $item['type_name'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['date'] ?></span></p>
                                        <p><span><?= $item['time_name'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['offline_from'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['server_name'] ?></span></p>
                                        <p><span><?= $item['server_phone'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['user_name'] ?></span></p>
                                        <p><span><?= $item['user_phone'] ?></span></p>
                                        <p><span><?= $item['address'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['start_time'] ?></span></p>
                                        <p><span><?= $item['end_time'] ?></span></p>
                                        <p><span><?= $item['use_time'] ?></span></p>
                                        <p><span><?= $item['server_num'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                       <!-- <p style="di"><span><?/*= $item['score_name'] */?></span></p>-->
                                        <p>
                                            <span style="display: block;line-height: 20px;max-height: 40px;overflow: hidden;">
                                                  <?php if ($item['stars'] > 0) : ?>
                                                <?= $item['stars'].'星。';?>
                                                  <?php endif; ?>

                                                  <?php if ($item['ping'] !='') : ?>
                                                      <?= $item['ping'];?>
                                                  <?php endif; ?>
                                            </span>
                                        </p>
                                    </td>
                                    <td class="am-text-middle" style="white-space: pre-line;">
                                        <p><span><?= $item['offline_name'] ?></span></p>
                                        <p><span><?= $item['remark'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['price'] * $item['server_num']?></span></p>
                                        <p><span><?= $item['service_prices']?></span></p>
                                        <p><span><?= $item['real_price'] ?></span></p>
                                    </td>
                                    <td class="am-text-middle">
                                        <p><span><?= $item['pay_status_name'] ?></span></p>
                                        <p><span><?= $item['is_offline'] ?></span></p>
                                        <p><span><?= $item['is_rec_text'] ?></span></p>
                                        <?php if ($item['is_rec'] == 1) : ?>
                                        <p><span>指派人：<?=  $item['p_service_name'] ?></span></p>
                                        <?php endif; ?>
                                    </td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <?php if ($item['pay_status'] == 0) : ?>
                                                <?php if (checkPrivilege('server.order/submit')): ?>
                                                    <a class="j-grade tpl-table-black-operation-default"
                                                       href="javascript:void(0);"
                                                       data-id="<?= $item['order_id'] ?>"
                                                       data-price="<?= $item['price'] * $item['server_num'] ?>"
                                                       data-service_id="<?= $item['service_id'] ?>"
                                                       data-service_price="<?=$item['service_prices']?>"
                                                       data-res_status="<?= $item['is_rec'] ?>"
                                                       title="审核服务佣金">
                                                        <i class="iconfont icon-grade-o"></i>
                                                        审核
                                                    </a>
                                                <?php endif; ?>
                                            <?php endif; ?>


                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach;
                            else: ?>
                                <tr>
                                    <td colspan="9" class="am-text-center">暂无记录</td>
                                </tr>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr"><?= $list->render() ?> </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：<?= $list->total() ?></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 模板：修改会员等级 -->
<script id="tpl-grade" type="text/template">
    <div class="am-padding-xs am-padding-top">
        <form class="am-form tpl-form-line-form" method="post" action="">
            <div class="am-tab-panel am-padding-0 am-active">
                <input type="hidden" name="service[order_id]" value="{{id}}">
                <input type="hidden" name="service[is_rec]" value="{{res_status}}">
                <input type="hidden" class="service_id" name="service_id" value="{{service_id}}">

                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label"> 开始时间 </label>
                    <div class="am-u-sm-9">
                        <!-- <input type="text" class="tpl-form-input am-form-field" name="withdraw[start_time]" placeholder="开始时间" name="withdraw[start_time]" data-am-datepicker required readonly
                               value=""> -->
                        <input class="start_time" type="date" onchange="upperCase()" >
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label"> 结束时间 </label>
                    <div class="am-u-sm-9">
                        <!-- <input type="text" class="tpl-form-input am-form-field" name="withdraw[start_time]" placeholder="开始时间" name="withdraw[start_time]" data-am-datepicker required readonly
                               value=""> -->
                        <input type="date" class="over_time" onchange="upperCase()">
                    </div>
                </div>

                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        累计时长
                    </label>
                    <div class="am-u-sm-8 am-u-end">
                        <input type="number" min="0" class="sum_money"
                               name="service[sum_time]" value="{{sum_time}}" readonly>
                    </div>
                </div>

                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        订单费用
                    </label>
                    <div class="am-u-sm-8 am-u-end">
                        <input type="number" min="0" class="tpl-form-input service-order-money"
                               name="service[order_money]" value="{{price}}" readonly>
                    </div>
                </div>

                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        服务金额
                    </label>
                    <div class="am-u-sm-8 am-u-end">
                        <input type="number" min="0" class="tpl-form-input service-money"
                               placeholder="请输入要服务的金额" name="service[service_money]" value="{{service_price}}" required>
                    </div>
                </div>

                <div class="am-form-group" id='tuijian'>
                    <label class="am-u-sm-3 am-form-label">
                        推荐人奖励
                    </label>
                    <div class="am-u-sm-8 am-u-end">
                        <input style="display:inline" type="number" class="tpl-form-input service-money"
                               placeholder="请输入推荐人奖励" name="service[p_bili]" value="" required>
                    </div>
                </div>

                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label">
                        奖惩金额
                    </label>
                    <div class="am-u-sm-8 am-u-end">
                        <input type="number" min="0" class="tpl-form-input service-reward-money"
                               placeholder="请输入奖惩金额" name="service[reward_money]" value="" required>
                    </div>
                </div>

                <div class="am-form-group">
                    <label class="am-u-sm-3 am-form-label"> 管理员备注 </label>
                    <div class="am-u-sm-8 am-u-end">
                                <textarea rows="2" name="service[remark]" placeholder="请输入管理员备注"
                                          class="am-field-valid service-remark"></textarea>
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>

<script>

    var obj = {}
    
    function upperCase(){
        var start_time = $('.start_time').val()
        var over_time = $('.over_time').val()
        if(start_time && over_time && obj){
            var dateTime = new Date(over_time)
            dateTime=dateTime.setDate(dateTime.getDate()+1);
            dateTime=new Date(dateTime);

            var year = dateTime.getFullYear();
            var month = dateTime.getMonth() + 1
            if (month < 10) month = "0" + month;
            var date = dateTime.getDate();
            if (date < 10) date = "0" + date;

            over_time = year + '-' + month + '-' + date
            console.log($('.service_id').val())


            $.post('index.php?s=/store/server.order/sum_money',{start_time:start_time,over_time:over_time,user_id:$('.service_id').val()},function(res){
                console.log(res)
                $('.sum_money').val(res.data)

            })
        }else{

        }
    }


    $(function () {
        /**
         * 修改会员等级
         */
        var div = `<div class="am-form-group" id='tuijian'>
                    <label class="am-u-sm-3 am-form-label">
                        推荐人比例
                    </label>
                    <div class="am-u-sm-8 am-u-end">
                        <input style="display:inline" type="number" min="0" max="100" class="tpl-form-input service-money"
                               placeholder="请输入百分比" name="p_bili" value="" required>
                    </div>
                    <div class="am-u-sm-1 am-u-end">
                        %
                    </div>
                </div>`
        $('.j-grade').on('click', function () {
            var data = $(this).data();
            console.log(data)
            $.showModal({
                title: '审核服务金额'
                , area: '460px'
                , content: template('tpl-grade', data)
                , uCheck: true
                , success: function ($content) {
                }
                , yes: function ($content) {
                    $content.find('form').myAjaxSubmit({
                        url: 'index.php?s=/store/server.order/submit',
                        data: {order_id: data.order_id}
                    });
                    return true;
                }
            });
            if(data.res_status === 0){
              $("#tuijian").hide()
            }else{
              $("#tuijian").show()
            }
        });

        /**
         * 订单导出
         */
        $('.j-export').click(function () {
            var data = {};
            var formData = $('#form-search').serializeArray();
            $.each(formData, function () {
                this.name !== 's' && (data[this.name] = this.value);
            });
            window.location = "<?= url('server.order/export') ?>" + '&' + $.urlEncode(data);
        });
    });


</script>

